﻿@model Bricks.Business.Models.Systems.DictionaryType

@{
    ViewBag.Title = "数据字典类型";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        //当页面首次刷新的时候执行的事件
        initTable();

        $('#embed').panel({
            href: '/Dictionary/Index?MenuCode=Dictionary'
        });
    });
    //实现对DataGird控件的绑定操作
    function initTable(queryData) {
        $('#dictionaryTypeGrid').datagrid({
            url: '/Dictionary/GetDictionaryTypeList',
            nowrap: true,
            autoRowHeight: false,
            singleSelect: true,
            striped: true,
            collapsible: true,
            pagination: false,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            queryParams: queryData,  //异步查询的参数
            toolbar: '#dictionaryTypeToolBar',
            columns: [[
                { title: '@Html.LabelFor(model => model.DictionaryTypeName)', field: 'DictionaryTypeName', width: 130, sortable: false },
                { title: '@Html.LabelFor(model => model.Tag)', field: 'Tag', width: 150, sortable: true }
            ]],
            onClickRow: function (index, row) {
                var selectedRow = $("#dictionaryTypeGrid").datagrid("getSelected");
                if (selectedRow) {
                    $('#dictionaryGrid').datagrid('load', { dictionaryTypeID: selectedRow.ID });
                }
            }
        });
    }
    var DictionaryType = {
        //新增
        Add: function () {
            DictionaryType.Mutual("新增", "/Dictionary/TypeEdit");
        },

        //修改
        Modify: function () {
            var row = $("#dictionaryTypeGrid").datagrid("getSelected");
            if (row) {
                DictionaryType.Mutual("修改", "/Dictionary/TypeEdit?ID=" + row.ID);
            }
            else { $.EasyuiSlide("请选择一条记录"); }
        },

        //实体操作
        Mutual: function (title, href) {
            $.ModelDialog({
                title: title, href: href, width: 320,
                handler: function () {
                    $.ModelForm({
                        validate: true, button: $(this),
                        id: "#dictoryType-model",
                        url: "/Dictionary/TypeEditPost",
                        success: function (result) { DictionaryType.Reload(); }
                    });
                },
                onLoad: function () { DictionaryType.FormInit(); }
            });
        },

        //弹窗初始化
        FormInit: function () {
            
        },

        //删除
        Delete: function () {
            var arr = $('#dictionaryTypeGrid').datagrid('getSelections');

            if (arr.length == 1) {
                $.messager.confirm('操作提示', "确认删除[ " + arr[0].DictionaryTypeName + " ]吗？", function (r) {
                    if (r) {
                        $.post("/Dictionary/DeleteDictionaryType?ID=" + arr[0].ID, { query: arr.join(",") }, function (result) {
                            if (result.ResultType == 0) {  //0表示成功
                                //移除删除的数据
                                //$("#dictionaryTypeGrid").datagrid("reload");
                                //$("#dictionaryTypeGrid").datagrid("clearSelections");
                                //$.messager.alert('操作提示', '删除成功!', 'info');
                                $.EasyuiSlide(result.Message);
                                DictionaryType.Reload();
                            }
                            else {
                                $.EasyuiMsg(result.Message);
                            }
                        });
                    }
                });

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;
        },

        //刷新重载
        Reload: function () {
            $("#dictionaryTypeGrid").datagrid("reload");  //注意此处是树表
        },

        //向上
        Up: function () {
            DictionaryType.Order("Up");
        },

        //向下
        Down: function () {
            DictionaryType.Order("Down");
        },

        //向上或向下方法
        Order: function (order) {
            var row = $("#dictionaryTypeGrid").datagrid("getSelected");
            if (row) {
                //id：识别当前记录；pid：识别涉及调整的记录集合；order：向上或向下
                $.post("/Dictionary/SetOrderDictionaryType", { id: row.ID, pid: row.PID, order: order }, function (result) {
                    if (result.ResultType == 0) {
                        $.EasyuiSlide(result.Message);  //成功则右下角提示
                        DictionaryType.Reload();
                        //$("#dictionaryTypeGrid").datagrid("selectRecord", row.ID);  //重新选中对应ID的记录（此处不生效，原因不明，后续探究）
                    }
                    else {
                        $.EasyuiMsg(result.Message);  //失败则弹出框提示
                    }
                });
            }
            else { $.EasyuiSlide(nullrowmsg); }
        }
    }
</script>

<div class="easyui-layout" data-options="fit:true">
    <div region="west" data-options="border:false" style="width: 320px;">
        <div class="easyui-panel" title="字典类型" fit="true">
            <table id="dictionaryTypeGrid" fit="true"></table>
            @*<div id="dictionaryTypeToolBar">
                <a href='javascript:void(0)' id='btnAdd' class='easyui-linkbutton' onclick='DictionaryType.Add()' data-options='plain:true,iconCls:"icon-add"'>新增</a>
                <a href='javascript:void(0)' id='btnModify' class='easyui-linkbutton' onclick='DictionaryType.Modify()' data-options='plain:true,iconCls:"icon-big_pencil"'>修改</a>
                <a href='javascript:void(0)' id='btnDelete' class='easyui-linkbutton' onclick='DictionaryType.Delete()' data-options='plain:true,iconCls:"icon-cancel"'>删除</a>
                <a href='javascript:void(0)' id='btnUp' class='easyui-linkbutton' onclick='DictionaryType.Up()' data-options='plain:true,iconCls:"icon-up"'>向上</a>
                <a href='javascript:void(0)' id='btnDown' class='easyui-linkbutton' onclick='DictionaryType.Down()' data-options='plain:true,iconCls:"icon-down"'>向下</a>
            </div>*@
            <div id="dictionaryTypeToolBar">@Html.Raw(ViewBag.ToolBarInfo)</div>
        </div>
    </div>
    <div region="center" style="border-left: 0px;height:500px;width:100%;">
        <div id="embed" class="easyui-panel" fit="true"></div>
    </div>
</div>